package Executor;


import lombok.Data;
import org.apache.ibatis.session.Configuration;
import org.assertj.core.util.Lists;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


public class MapperInterfaceEnhance {
  private static int size = 1000000;
  private static Map<Object, Object> objectMap = new ConcurrentHashMap<>(size);
  private static NickLock nicklock = new NickLock();

  @Data
  static class MapperScanner {
    private String mapperLocation;

    /**
     * TODO Mapper 扫描过程
     *
     * @return 返回包扫描
     */
    List<Object> scanMapper() {
      List<Object> objects = Lists.newArrayList();
      for (int i = 0; i < size; i++) {
        objects.add(new Object());
      }
      return objects;
    }
  }

  public static void put(Object obj) {
    objectMap.put(obj, obj);
  }


  public static void main(String[] args) {
    String mapperLocation = "classpath:mapper/*.xml";

    MapperScanner mapperScanner = new MapperScanner();
    mapperScanner.setMapperLocation(mapperLocation);

    List<Object> objects = mapperScanner.scanMapper();
//    Configuration configuration = new Configuration();
//    /*
//     * 多线程遍历输入
//     */
//    classes
//      .parallelStream()
//      .forEach(configuration::addMapper);

    long start = System.currentTimeMillis();
    objects
      .parallelStream()
      .forEach(MapperInterfaceEnhance::put);
    long end = System.currentTimeMillis();
    System.out.println(end - start);
  }


}
